package maven.demo5;

/**
 *  exception chain: 异常链
 *  tips: 抛出异常的一级级传递
 */
public class ExceptionChain {
    public void test1() throws CustomException {
        throw new CustomException("喝酒别开车！");
    }

    public void testExceptionChain() {
        try {
            test1();
        } catch (CustomException e) {
            // 捕捉 CustomException 后，抛出 RuntimeException 异常

            // 形式1：自定义抛出的异常信息
//            RuntimeException newExc = new RuntimeException("司机一滴酒，亲人两行泪");
//            newExc.initCause(e);
//            throw newExc;

            // 形式2：异常信息取决于内部抛出的异常
            RuntimeException newExc = new RuntimeException(e);
            throw newExc;
        }
    }
}
